package com.eddie.principle.inversion;

/**
 * @author Eddie
 * @date 2022/4/27 13:41
 */
public class DependencyInversion {

    public static void main(String[] args) {
        //客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeChat());
    }

}

/**
 * 定义一个接口
 */

interface IReceiver {
    String getInfo();
}

class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "电子邮件信息：HelloWorld";
    }
}


class WeChat implements IReceiver {
    @Override
    public String getInfo() {
        return "微信消息：Hello,Ok";
    }
}

/**
 * 方式2
 **/
class Person {
    public void receive(IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}
